package ycl.base.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ycl.base.entity.UserFiles;
import ycl.base.req.UserFilesReq;
import ycl.base.res.UserFilesRes;
import ycl.base.service.UserFilesService;
import ycl.common.result.Result;
import ycl.common.base.controller.BaseController;
import ycl.common.result.REnum;
import ycl.common.exception.CustomException;
import ycl.common.models.base.A;
import ycl.common.models.req.IdNameReq;
import ycl.common.models.req.base.ObjReq;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 用户文件控制器
 *
 * @author ycl
 * @date 2022/7/7 0007 14:31:54
 */
@RestController
@RequestMapping("user-files")
@ApiSupport(order = 4)
@Api(tags = "用户文件管理")
public class UserFilesController
		extends BaseController<UserFiles, UserFilesReq, UserFilesRes> {

	@Resource
	private UserFilesService userFilesService;

	@Override
	public Result<Page<UserFilesRes>> pageList(HttpServletRequest request, UserFiles publicFiles) {
		Page<UserFilesRes> page = userFilesService.pageList(request, publicFiles, UserFilesRes.class);
		return Result.success(page);
	}

	@Override
	@ApiOperation(value = "保存", hidden = true)
	public <E extends UserFilesReq> Result<A> save(HttpServletRequest request, @RequestBody E e) {
		throw new CustomException(REnum.CUSTOM_SERVER_REJECT);
	}

	@Override
	public Result<UserFiles> deleteBatchIds(HttpServletRequest request, @RequestBody ObjReq<List<Long>> req) {
		userFilesService.deleteBatchIds(request, req.getObj());
		return Result.success();
	}

	@Override
	@ApiOperation(value = "修改", hidden = true)
	public <E extends UserFilesReq> Result<A> update(HttpServletRequest request, @RequestBody E e) {
		throw new CustomException(REnum.CUSTOM_SERVER_REJECT);
	}

	@ApiOperation(value = "重命名")
	@PostMapping("rename")
	@ApiOperationSupport(order = 11)
	public Result<A> rename(HttpServletRequest request, @RequestBody IdNameReq req){
		 userFilesService.rename(request, req);
		 return Result.success();
	}
}
